<?php

namespace Futures\Controller;
use Futures\Model\OptionModel;
use Think\Controller;

/**
 *  经纪人申请模块
 */
class ApplyController extends BaseController{
	
	public function index(){
		//获取用户id
		$user_auth= cookie('user_auth');
		$user_id = $user_auth['uid'];
		//获取用户信息
		$user_data = M('follow')->where('id='.$user_id)->field('is_agent')->find();
		$where['user_id'] = $user_id;
		$where['status'] = 0;
		//判断是否已经提交过经纪人申请$apply_status = 0;
		$apply = M('Futures_agent_apply')->where($where)->find();
		if($apply){
			$apply_status = 1;
		}else{
			$apply_status = 0;
		}
		//判断是否为经纪人
		if($user_data['is_agent'] != 1){
			$this->assign('apply_status',$apply_status);
			$this->assign('user_id',$user_id);
			$this->display('index');
		}else{
			$this->redirect('Commission/index');
		}
    }
    
    //提交申请
    public function Apply(){
    	//$error['info'] = "申请成功";
    	
    	//$this->ajaxReturn($error,'JSON');
    	//$data['user_id'] = $_GET['id'];
    	$data['user_id'] = I('post.id');
		$data['apply_time'] = time();
		$data['status'] = 0;
		$res = M('FuturesAgentApply')->add($data);
		if(false === $res){
			$this->error('申请失败！');
		}else{
			$this->success('申请成功！');
		}
    	//$this->redirect('Apply/index'); 
    }
}
